import {Component, VNode} from "@vue/runtime-core";
import {createApp} from "vue";
import CdlDrawer from "@/components/drawer/index"
import {directive} from "@/utils/directive";

export function createDrawer(ti: string, vNode: VNode | Component, callFun: (data: any)=> void) {
    console.log("创建Drawer抽屉。。。")
    let div: HTMLDivElement = document.createElement("div")
    div.setAttribute("id", "cdl_drawer")
    div.style.cssText = "position: absolute; z-index: 998; width: 100%; height: 100%; top: 0"
    document.body.appendChild(div)

    const drawer = createApp(CdlDrawer, {
        title: ti,
        vNode: vNode,
        callFun: callFun,
    })
    directive(drawer)
    drawer.provide("destroyDrawer", destroyDrawer)
    drawer.mount("#cdl_drawer")

    function destroyDrawer(){
        drawer.unmount()
        div.remove()
    }
}
